package com.fengye.school.model.school;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fengye.school.model.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * 专业表
 * @author sky
 * @since 2021/4/22 10:31 上午
 */
@Table(name = "tb_s_major")
@org.hibernate.annotations.Table(appliesTo = "tb_s_major", comment = "专业表")
@Entity
@Getter
@Setter
public class Major extends BaseEntity {
    @Column(name ="full_name", columnDefinition = "varchar(100) COMMENT '专业全名称'")
    private String fullName;

    @Column(name ="short_name", columnDefinition = "varchar(50) COMMENT '专业短名称'")
    private String shortName;

    @Column(name ="sketch", columnDefinition = "varchar(255) COMMENT '专业简述'")
    private String sketch;

    @Column(name ="`description`", columnDefinition = "varchar(255) COMMENT '专业完整表述'")
    private String description;

    @Column(name = "`establish_time`", columnDefinition = "datetime COMMENT '创建时间'")
    private Date establishTime;

    @JsonIgnore
    @OneToMany(mappedBy = "major", targetEntity = EClass.class)
    private Set<EClass> eClassSet;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "school_id")
    private School school;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Major)) return false;
        if (!super.equals(o)) return false;

        Major major = (Major) o;

        return getId() == (major.getId());
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + getCreateTime().hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Major{" +
                "id='" + getId() + '\'' +
                "fullName='" + fullName + '\'' +
                ", shortName='" + shortName + '\'' +
                ", sketch='" + sketch + '\'' +
                ", description='" + description + '\'' +
                ", establishTime=" + establishTime +
                ", createTime="+ getCreateTime() +
                ", updateTime="+ getUpdateTime() +
                '}';
    }
}
